<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryRef"
      :inline="true"
      v-show="showSearch"
    >
      <el-form-item label="订单编号:" prop="queryOrederId">
        <el-input
          v-model="queryParams.queryOrederId"
          placeholder="根据订单编号搜索"
          clearable
          style="width: 200px"
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="商品名称:" prop="queryGoodsId">
        <el-select
                :style="{ width: '100%' }"
                v-model="queryParams.queryGoodsId"
                filterable
                remote
                reserve-keyword
                placeholder="请输入商品名称搜索"
                :remote-method="remoteMethodGoods"
                :loading="loadingGoods"
              >
                <el-option
                  v-for="item in optionsGoodsList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
           </el-select>
      </el-form-item>
      <el-form-item label="画师:" prop="queryPainterQQ">
              <el-select
                :style="{ width: '100%' }"
                v-model="queryParams.queryPainterQQ"
                filterable
                remote
                reserve-keyword
                placeholder="请输入画师昵称搜索画师"
                :remote-method="remoteMethod2"
                :loading="loadingGoods"
                clearable
              >
                <el-option
                  v-for="item in optionsPainterList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            
      </el-form-item>
      <el-form-item label="购买人qq号:" prop="queryBuyerQQ">
        <el-input
          v-model="queryParams.queryBuyerQQ"
          placeholder="根据qq号搜索"
          clearable
          style="width: 120px"
          @keyup.enter="handleQuery"
        />
      </el-form-item>

      <el-form-item label="被赞人qq号:" prop="querySponsorQQ">
        <el-input
          v-model="queryParams.querySponsorQQ"
          placeholder="根据qq号搜索"
          clearable
          style="width: 120px"
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="转出人qq号:" prop="queryTransferQQ">
        <el-input
          v-model="queryParams.queryTransferQQ"
          placeholder="根据qq号搜索"
          clearable
          style="width: 120px"
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="微店订单id:" prop="queryWdId">
        <el-input
          v-model="queryParams.queryWdId"
          placeholder="根据微店订单id搜索"
          clearable
          style="width: 180px"
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="购买日期:">
        <el-date-picker
          style="width: 220px"
          v-model="dateRange"
          value-format="YYYY-MM-DD"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订单类型:" prop="queryType">
        <el-select :style="{ width: '100px' }" v-model="queryParams.queryType" placeholder="请选择" clearable>
          <el-option v-for="item in typeList" :key="item.value" :label="item.label" :value="item.value" />
        </el-select>
      </el-form-item>


      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
 
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['add']" 
          type="primary"
          plain
          icon="Plus"
          @click="handleAdd"
          >新增</el-button
        >
      </el-col>
 
      <el-col :span="1.5">
        <el-button
        v-hasPermi="['del']" 
          type="danger"
          plain
          icon="Delete"
          :disabled="multiple"
          @click="handleDelete"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
        v-hasPermi="['update']" 
          type="primary"
          plain
          icon="Upload"
          @click="handleUpload"
          >导入</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
        v-hasPermi="['export']" 
          type="primary"
          plain
          icon="Download"
          @click="handleExport"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        v-model:showSearch="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="pageList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" type="index" width="60" />
      <el-table-column label="订单编号" align="center" prop="id" width="150" />
      <el-table-column
        label="商品名称"
        align="center"
        prop="goodsName"
        width="250"
        :show-overflow-tooltip="true"
      >
       
      </el-table-column>
      <el-table-column
        label="平台"
        align="center"
        prop="platform"
        width="150"
      />
 
      <el-table-column
        label="购买人qq号"
        align="center"
        prop="buyerQQ"
        width="150"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="购买人昵称"
        align="center"
        prop="buyerQQNickName"
        width="150"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="购买人店铺昵称"
        align="center"
        prop="buyerQQAliasNickName"
        width="150"
        :show-overflow-tooltip="true"
      />
      

      <el-table-column
        label="购买日期"
        align="center"
        prop="buyDate"
        width="100"
      >
        <template #default="scope">
          <span>{{ parseTime(scope.row.buyDate, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="是否转让"
        align="center"
        prop="takeoutStatus"
        width="250"
        show-overflow-tooltip
      >
        <template #default="scope">
          <div
            class="green"
            :class="{ red: handleShowTakeOut(scope.row).code != 1 }"
          >
            {{ handleShowTakeOut(scope.row).txt }}
          </div>
        </template>
      </el-table-column>
      <el-table-column
        label="转出人qq号"
        align="center"
        prop="transferQQ"
        width="120"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="转出人昵称"
        align="center"
        prop="transferQQNickName"
        width="120"
        :show-overflow-tooltip="true"
      />
            <el-table-column
        label="转出日期"
        align="center"
        prop="transferDate"
        width="100"
      >
        <template #default="scope">
          <span>{{ parseTime(scope.row.transferDate, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="被赞人qq号"
        align="center"
        prop="sponsorQQ"
        width="120"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="被赞人昵称"
        align="center"
        prop="sponsorQQNickName"
        width="120"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="赞助日期"
        align="center"
        prop="sponsorDate"
        width="100"
      >
        <template #default="scope">
          <span>{{ parseTime(scope.row.sponsorDate, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="订单类型"
        align="center"
        prop="type"
        width="100"
      >
        <template #default="scope">
          <dict-tag :options="typeList" :value="scope.row.type" />
        </template>
      </el-table-column>

      <el-table-column
        label="商品所属画师"
        align="center"
        prop="goodsPainterQQ"
        width="120"
      >
        <template #default="scope">
          <dict-tag :options="painterList" :value="scope.row.goodsPainterQQ" />
        </template>
      </el-table-column>

 
      <el-table-column
        label="价格"
        align="center"
        prop="buyPrice"
        width="100"
      />
      <el-table-column
        label="售卖数量"
        align="center"
        prop="buySum"
        width="100"
      />

      <el-table-column
        label="数据来源"
        align="center"
        prop="origin"
        width="100"
      >
        <template #default="scope">
          <dict-tag :options="originList" :value="scope.row.origin" />
        </template>
      </el-table-column>
      <el-table-column
        label="订单备注"
        align="center"
        prop="remarks"
        width="200"
        :show-overflow-tooltip="true"
      />
    <el-table-column
        label="关联微店编号"
        align="center"
        prop="wdId"
        width="200"
       >
      
      </el-table-column>  
      
      <el-table-column
        label="更新日期"
        align="center"
        prop="updatedAt"
        width="180"
      >
        <template #default="scope">
          <span>{{ parseTime(scope.row.updatedAt, "{y}-{m}-{d}  {hh}:{mm}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        width="200"
        :fixed="desk"
        class-name="small-padding fixed-width"
      >
        <template #default="scope">
          <el-button
          v-hasPermi="['edit']" 
            link
            type="primary"
            icon="Edit"
            @click="handleUpdate(scope.row)"
            >修改</el-button
          >
          <el-button
          v-hasPermi="['del']" 
            link
            type="primary"
            icon="Delete"
            @click="handleDelete(scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改公告对话框 -->
    <el-dialog :title="title" v-model="open" width="520px" append-to-body>
      <el-form ref="noticeRef" :model="form" :rules="rules" label-width="120px">
        <el-row>
          <el-col :span="23">
            <el-form-item label="商品名称:" prop="goodsId">
              <el-select
                :style="{ width: '100%' }"
                v-model="form.goodsId"
                filterable
                remote
                reserve-keyword
                placeholder="请输入商品名称搜索"
                :remote-method="remoteMethodGoods"
                :loading="loadingGoods"
              >
                <el-option
                  v-for="item in optionsGoodsList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="23">
            <el-form-item label="平台:" prop="platform">
              <el-input v-model="form.platform" placeholder="输入平台" />
            </el-form-item>
          </el-col>
          <el-col :span="23"  >
            <el-form-item label="购买用户QQ:" prop="buyerQQ">
              <el-input v-model="form.buyerQQ" placeholder="输入qq号" />
            </el-form-item>
          </el-col>
 
          <el-col :span="23" >
            <el-form-item label="转出人QQ:" prop="transferQQ">
              <el-input v-model="form.transferQQ" placeholder="输入qq号" />
            </el-form-item>
          </el-col>
           <el-col :span="23">
            <el-form-item label="转出日期:" prop="transferDate">
              <el-date-picker
                v-model="form.transferDate"
                type="date"
                placeholder="请选择转出日期"
                format="YYYY/MM/DD"
                value-format="YYYY-MM-DD"
              />
            </el-form-item>
          </el-col>
          <el-col :span="23" >
            <el-form-item label="被赞人QQ:" prop="sponsorQQ">
              <el-input v-model="form.sponsorQQ" placeholder="输入qq号" />
            </el-form-item>
          </el-col>
        <el-col :span="23">
            <el-form-item label="赞助日期:" prop="sponsorDate">
              <el-date-picker
                v-model="form.sponsorDate"
                type="date"
                placeholder="请选择赞助日期"
                format="YYYY/MM/DD"
                value-format="YYYY-MM-DD"
              />
            </el-form-item>
          </el-col>
          <el-col :span="23">
            <el-form-item label="购买日期:" prop="buyDate">
              <el-date-picker
                v-model="form.buyDate"
                type="date"
                placeholder="请输入开始售卖日期"
                format="YYYY/MM/DD"
                value-format="YYYY-MM-DD"
              />
            </el-form-item>
          </el-col>
          <el-col :span="23">
            <el-form-item label="购买价格:" prop="buyPrice">
              <el-input-number v-model="form.buyPrice" :min="0" :max="999999" />
            </el-form-item>
          </el-col>
          <el-col :span="23">
            <el-form-item label="购买数量:" prop="buySum">
              <el-input-number 
              :disabled = "title == '修改'"
              v-model="form.buySum" :min="0" :max="9999" />
            </el-form-item>
          </el-col>
          <el-col :span="23"  >
            <el-form-item label="订单类型" prop="type">
              <el-select v-model="form.type" clearable placeholder="请选择">
                <el-option
                  v-for="item in typeList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
   
           <el-col :span="23">
            <el-form-item label="绑定微店单编号:" prop="wdId">
              <el-input v-model="form.wdId" placeholder="输入微店订单编号" />
            </el-form-item>
          </el-col>
          
          <el-col :span="23">
            <el-form-item label="备注:" prop="remarks">
              <el-input
                v-model="form.remarks"
                :autosize="{ minRows: 2, maxRows: 4 }"
                type="textarea"
                placeholder="订单备注信息"
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button
            type="primary"
            @click="debouncedFn"
            :loading="loadingSubmit"
            >确 定</el-button
          >
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>

    <!-- 添加或修改公告对话框 -->
    <el-dialog
      :title="title"
      v-model="dialogOpen2"
      width="780px"
      append-to-body
    >
      <el-form ref="orderRef2" :model="dialogForm2" label-width="120px">
        <el-row>
          <el-col :span="23">
            <el-form-item label="模板下载">
              <el-button type="primary" @click="submitUploadFileDemo"
                >下载xlsx模板</el-button
              >
            </el-form-item>
          </el-col>
          <el-col :span="23">
            <el-form-item label="附件上传">
              <el-upload
                class="upload-demo"
                :action="uploadUrl"
                :on-change="handleChange"
                :file-list="fileList"
                :before-upload="beforeAvatarUpload"
                :on-success="onSuccessImg"
              >
                <el-button type="primary">点击上传</el-button>
                <div slot="tip" class="el-upload__tip">请按模板规范上传</div>
              </el-upload>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="dialogCancel2">取 消</el-button>
        </div>
      </template>
    </el-dialog>
 
     <!-- 导出 按钮 -->
     <el-dialog
      :title="title"
      v-model="dialogOpen1"
      width="780px"
      append-to-body
    >
      <el-form ref="orderRef1" :model="dialogForm1" label-width="120px">
        <el-row>
          <el-col :span="18">
            <el-form-item label="商品名称" prop="goodsId">
              <el-select
                :style="{ width: '100%' }"
                v-model="dialogForm1.goodsId"
                clearable
                filterable
                remote
                reserve-keyword
                placeholder="请输入商品名称搜索"
                :remote-method="remoteMethodGoods"
                :loading="loadingGoods"
              >
                <el-option
                  v-for="item in optionsGoodsList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col>
            备注：选择对应商品导出对应商品订单，如果不选商品则导出全部订单。
          </el-col>
        </el-row>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitExport" :loading="loadingBtn"
            >确 定</el-button
          >
          <el-button @click="dialogCancel1">取 消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="Order">
import {
  listOrder,
  addOrder,
  updateOrder,
  deleteOrder,
  downExcelOrder,
  downExcelFile,
} from "@/api/business/order";
import {} from "@/api/business/goods";

 
import { listGoods  } from "@/api/business/goods";
import { listUser , listAllUser} from "@/api/business/user";
 
import { useDebounceFn } from "@vueuse/core";
import useDesk from "@/hooks/useDesk";
import { orderTypeEnums ,orderStatusEnums ,originEnums  } from "@/utils/enums"

const { desk } = useDesk();
const { proxy } = getCurrentInstance();
// 图片上传地址
const uploadUrl = import.meta.env.VITE_APP_UPLOAD_API + "api/uploadFile/file";
const uploadUrl1 =
  import.meta.env.VITE_APP_UPLOAD_API + "api/uploadFileEdit/file";
const uploadShowUrl = import.meta.env.VITE_APP_COS_API;

const imgSrc = ref("");
const pageList = ref([]);
const open = ref(false);

const dialogOpen1 = ref(false); // 导出表格
const dialogOpen2 = ref(false); // 导入表格
 

const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");
const painterList = ref([]); // 画师下拉框
const useOtherPlatformList = ref([
  { label: "是", value: "是" },
  { label: "否", value: "否" },
]);
// 是否赞助
const statusComList = ref([
  { label: "否", value: 1 },
  { label: "是", value: 2 },
]);

 
const loadingGoods = ref(false);

const optionsPainterList = ref([]);  
const optionsGoodsList = ref([]);  

const optionsUser = ref([]); //  用户搜索
const loadingUser = ref(false);
 
const loadingSubmit = ref(false);
const loadingBtn = ref(false);
const fileList = ref([]);

const dateRange = ref([]);
 
const takeoutStatusList = ref([
  {
    label: "可以转让",
    value: "1",
    elTagClass: "",
    elTagType: "success",
  },
  {
    label: "禁止转让：商品禁止转让",
    value: "2",
    elTagClass: "",
    elTagType: "danger",
  },
  {
    label: "禁止转让：订单已经被转让过了",
    value: "3",
    elTagClass: "",
    elTagType: "danger",
  },
  {
    label: "禁止转让：购买日期不在3个月至1年之内",
    value: "4",
    elTagClass: "",
    elTagType: "danger",
  },
]);
 
const data = reactive({
  typeList:orderTypeEnums,
  statusList:orderStatusEnums,
  originList:originEnums,
  form: {},
  dialogForm1: {
    goodsId: undefined,
    beginTime: undefined,
    end: undefined,
    painterId: undefined,
  }, // 导出弹出框选择
  dialogForm2: {
    goodsId: undefined,
  }, // 导出弹出框选择
 
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    queryOrederId: undefined,
    queryGoodsId: undefined,
    queryPainterQQ: undefined,
    queryUserName: undefined,
    queryTransferQQ: undefined,
    queryStartEndTime: undefined,
  },
  rules: {
    goodsId: [{ required: true, message: "商品名称不能为空", trigger: "blur" }],
    buyerQQ: [
      { required: true, message: "购买用户QQ不能为空", trigger: "change" },
    ],
    type: [
      { required: true, message: "订单类型不能为空", trigger: "change" },
    ],
 
  },
});

const { queryParams, form, dialogForm1,
  typeList,
  statusList,
  originList,
  dialogForm2,  rules } =
  toRefs(data);

/** 查询公告列表 */
function getList() {
  loading.value = true;
 
  listOrder(proxy.addDateRangeZL(queryParams.value, dateRange.value)).then(
    (response) => {
      pageList.value = response.data.rows;

      total.value = response.data.count;
      loading.value = false;
    }
  );
}
/** 取消按钮 */
function cancel() {
  open.value = false;
  reset();
}
/** 新增表单重置 */
function reset() {
 
  form.value = {
    buyPrice:0,
    buySum:1,
    platform:'易次元',
    type :1,
    buyDate: proxy.parseTime(new Date(), "{y}/{m}/{d}")
  };
  data.rules = {
    goodsId: [{ required: true, message: "商品名称不能为空", trigger: "blur" }],
    buyerQQ: [
      { required: true, message: "购买用户QQ不能为空", trigger: "change" },
    ],
    type: [
      { required: true, message: "订单类型不能为空", trigger: "change" },
    ],
  };
  proxy.resetForm("noticeRef");
}

 

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}
/** 重置按钮操作 */
function resetQuery() {
  dateRange.value = [];
  proxy.resetForm("queryRef");
  handleQuery();
}
/** 多选框选中数据 */
function handleSelectionChange(selection) {
  ids.value = selection.map((item) => item.id);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}
/** 新增按钮操作 */
function handleAdd() {
  reset();
  open.value = true;
  title.value = "新增";
}

/** 取消按钮 */
function dialogCancel1() {
  dialogOpen1.value = false;
  dialogReset1();
}
/** 取消按钮 */
function dialogCancel2() {
  dialogOpen2.value = false;
  dialogReset2();
}
 
function handleExport() {
  dialogReset1();
  dialogOpen1.value = true;
  title.value = "导出表格";
}
/** 导入表格 */
function handleUpload() {
  dialogReset2();
  dialogOpen2.value = true;
  title.value = "导入表格";
}

/** 表单重置 */
function dialogReset1() {
  proxy.resetForm("orderRef1");
}

/** 表单重置 */
function dialogReset2() {
  proxy.resetForm("orderRef2");
  fileList.value = [];
}

 
 

/**修改按钮操作 */
function handleUpdate(row) {
  reset();

  if (!row.id) {
    let arr = pageList.value.filter((item) => {
      return item.id == ids.value;
    });
    form.value = {
      ...arr[0],
      name: arr[0].goodsName,
    };
  } else {
    form.value = {
      ...row
    };
 
    optionsGoodsList.value = [
      {
        label: row.goodsName,
        value: row.goodsId,
      },
    ];
 
  }
  title.value = "修改";
  open.value = true;
}

// 防抖操作
const debouncedFn = useDebounceFn(
  () => {
    submitForm();
  },
  1000,
  { maxWait: 3000 }
);

/** 提交按钮 */
function submitForm() {
  proxy.$refs["noticeRef"].validate((valid) => {
    if (valid) {
      loadingSubmit.value = true;
      if (form.value.id != undefined) {
        
        updateOrder(form.value)
            .then((response) => {
              proxy.$modal.msgSuccess("修改成功");
              loadingSubmit.value = false;
              open.value = false;

              getList();
            })
            .catch(() => {
              loadingSubmit.value = false;
            });
      } else {
 
        addOrder(form.value)
            .then((response) => {
              proxy.$modal.msgSuccess("新增成功");
              loadingSubmit.value = false;
              open.value = false;

              getList();
            })
            .catch(() => {
              loadingSubmit.value = false;
            });
   
      }
    }
  });
}
/** 删除按钮操作 */
function handleDelete(row) {
  let deleteId = row.id || ids.value;
  if (!Array.isArray(deleteId)) {
    deleteId = [deleteId];
  }
  let arrList = pageList.value.filter((item) => {
    return;
  });
  proxy.$modal
    .confirm('是否确认删除编号为"' + deleteId + '"的数据项？')
    .then(function () {
      return deleteOrder({ id: deleteId });
    })
    .then(() => {
      getList();
      proxy.$modal.msgSuccess("删除成功");
    })
    .catch(() => {});
}
/** 商品名远程搜索 */
function remoteMethodGoods(query) {
  if (query) {
    loadingGoods.value = true;
    let queryParams = {
      pageNum: 1,
      pageSize: 50,
      queryGoodsName: query,
    };
    listGoods(queryParams).then((response) => {
     
      optionsGoodsList.value = response.data.rows.map((item) => {
        return {
          label: item.name,
          value: item.id,
        };
      });

      loadingGoods.value = false;
    });
  } else {
    optionsGoodsList.value = [];
  }
}
 

/** 画师远程搜索 */
function remoteMethod2(query) {
  if (query) {
    loadingGoods.value = true;
    let queryParams = {
      pageNum: 1,
      pageSize: 50,
      queryNickname: query,
      type:3
    };
    listUser(queryParams).then((response) => {
      optionsPainterList.value = response.data.rows.map((item) => {
        return {
          label: item.nickname,
          value: item.id,
        };
      });

      loadingGoods.value = false;
    });
  } else {
    optionsPainterList.value = [];
  }
}
 


/** 导出 */
function submitExport() {
  const dataForm = dialogForm1.value;
  let fileName = "订单";
  if (dataForm.queryDate) {
    fileName = fileName + dataForm.queryDate + ".xlsx";
  } else {
    fileName = fileName + ".xlsx";
  }
  if (dataForm.queryDate) {
    let Time = dataForm.queryDate;
    let y = new Date(Time).getFullYear(); //获取年份
    let m = new Date(Time).getMonth() + 1; //获取月份
    let begin = Time + "-01";
    let end = Time + "-" + new Date(y, m, 0).getDate(); //获取当月最后一日
    dataForm.beginTime = begin;
    dataForm.endTime = end;
  } else {
    dataForm.beginTime = undefined;
    dataForm.endTime = undefined;
  }
  loadingBtn.value = true;

 
  downExcelOrder(dataForm).then((response) => {
    loadingBtn.value = false;

    downFile(response, fileName);
  });
}
// 可以将此方法封装
function downFile(content, filename) {
  // 创建隐藏的可下载链接
  var eleLink = document.createElement("a");
  eleLink.download = filename;
  eleLink.style.display = "none";
  // 字符内容转变成blob地址
  var blob = new Blob([content]);
  eleLink.href = URL.createObjectURL(blob);
  document.body.appendChild(eleLink);
  // 触发点击
  eleLink.click();
  // 然后移除
  document.body.removeChild(eleLink);
  proxy.$modal.msgSuccess("操作成功");
}
// dialogForm1.painterId
/** 商品名远程搜索 */
function remoteMethodGoods1(query) {
  
  queryGoodsName(query)
}

/** 上传用 */
function beforeAvatarUpload(rawFile) {
  if (rawFile.size / 1024 / 1024 > 2) {
    proxy.$modal.msgError("  文件大于 2MB!");
    return false;
  }
  return true;
}
function onSuccessImg(response) {
  if (response.code == 200) {
    proxy.$modal.msgSuccess(response.msg);
    getList();
  } else {
    proxy.$modal.msgError(response.msg);
  }
}

/** 下载标准模板 */
function submitUploadFileDemo(response) {
  let fileName = "无言订单标准模板2025.xlsx";
  loadingBtn.value = true;
  downExcelFile({}).then((response) => {
    loadingBtn.value = false;
    downFile(response, fileName);
  });
}

/** 判断是否可以转让 */
function handleShowTakeOut(row) {
  
 
  let goodsStatus = row.goodsStatus; // 商品转让状态- 首先判定
  let goodsType = row.goodsType; // 商品类型  1限时  2限量  3其他

  let orderType = row.type; // 订单的转让状态   2转让单  3待赠单  4已赠单
  let arr = []
  
  // 第一层 条件
  if (goodsStatus == 2) {
    arr.push({
      code: 1,
      txt: "禁止转让：商品禁止转让",
    })
  }
  // 第二层 条件
  if(orderType == 1){
    arr.push({
      code: 200,
      txt: "可以转让",
    })
  }else if(orderType == 2) {
    arr.push({
      code: 2,
      txt: "禁止转让：订单已经被转让过了",
    })
  }else if( orderType == 3){
    arr.push({
      code: 3,
      txt: "禁止转让：待赠单无法转让",
    })
  }else if(orderType == 4 ){
    arr.push({
      code: 4,
      txt: "禁止转让：已赠单无法转让",
    })
  }
  // 第三层 条件
  let flag = arr.filter((item)=>{return item.code < 200})

  
  if(flag && flag.length>0){
    let errorStr = ''
    flag.forEach((item)=>{
      errorStr += item.txt+','
    })
    return {
      code :0,
      txt:errorStr
    }
  } 

  return {
    code:200,
    txt: "可以转让",
  }
 
}
/** 查询画师列表 */
function getPainterList() {
  listAllUser({
    type:3
  }).then((response) => {
    painterList.value = response.data.map((item) => {
      return {
        label: item.nickname||'-空-',
        value: item.id,
        elTagType:'default' //不需要tag标签
      };
    });
  });
}

watch(
  () => data.dialogForm1.painterId,
  (newValue, oldValue) => {
    if (newValue !== oldValue) {
      goodsHttp(); // 重新搜索
      data.dialogForm1.goodsId = undefined;
    }
  },
  { deep: true }
);

getList();
 
getPainterList(); // 画师列表
</script>
<style lang="scss" scoped>
.goods-name {
  color: rgb(0, 119, 255);
  cursor: pointer;
}
.green {
  color: #2eacf5;
}
.red {
  color: red;
}
</style>
